
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include('shared.lua')

function ENT:Initialize()   

	math.randomseed(CurTime())

	//self.firesound = "spacemarine/plasma_rifle.wav"

	self.exploded = false
	self.Entity:SetModel( "models/dav0r/hoverball.mdl" ) 	
	self.Entity:PhysicsInit( SOLID_VPHYSICS )      -- Make us work with physics,  	
	self.Entity:SetMoveType( MOVETYPE_VPHYSICS )   --after all, gmod is a physics  	
	self.Entity:SetSolid( SOLID_VPHYSICS )        -- Toolbox  
	self.Entity:SetMaterial("models/props_combine/portalball001_sheet")   
	//self.Entity:SetColor(0,191,255,235)
	self.Entity:Ignite( 120, 40 )
	
	self.dietime = CurTime() + 3
	//local Sprite = ents.Create("env_sprite");
	//Sprite:SetKeyValue( "renderfx", "14" )
	//Sprite:SetKeyValue( "model", "sprites/glow02.vmt")
	//Sprite:SetKeyValue( "scale", "0.18")
	//Sprite:SetKeyValue( "spawnflags", "1")
	//Sprite:SetKeyValue( "angles", "0 0 0")
	//Sprite:SetKeyValue( "rendermode", "9")
	//Sprite:SetKeyValue( "renderamt", "220")
	//Sprite:SetKeyValue( "rendercolor", "0 191 255" )
	//Sprite:Spawn()
	//Sprite:Activate()
	//Sprite:SetParent( Entity )
	
	//self.Entity:EmitSound( self.firesound , 500 , 100 )
	local phys = self.Entity:GetPhysicsObject()  	
	if (phys:IsValid()) then 		
		phys:Wake()  
		phys:EnableGravity(false)
	end 
	//self:SetGravity(0.25)
	
end   

function ENT:OnTakeDamage( dmginfo )
	
	self.Entity:TakePhysicsDamage( dmginfo )
	
end

function ENT:PhysicsCollide()
	if ( self.exploded == false) then
		util.BlastDamage(self.Entity, self.Entity, self.Entity:GetPos(), 70, 30)
		
		local effectdata = EffectData()
		effectdata:SetOrigin(self.Entity:GetPos())
		//util.Effect( "ImpactGunship", effectdata )
		
		self.exploded = true
	end
end

function ENT:Think()

if ( self.dietime < CurTime() ) then
		util.BlastDamage(self.Entity, self.Entity, self.Entity:GetPos(), 70, 30)
		
		local effectdata = EffectData()
		effectdata:SetOrigin(self.Entity:GetPos())
		//util.Effect( "ImpactGunship", effectdata )
		
		self.exploded = true
	end

if self.exploded == true then self:Remove() end
self:NextThink( CurTime() )
return true
end
 
